import com.sun.rowset.CachedRowSetImpl;
import java.sql.SQLException;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author tub
 */
public class SearchTableModel extends AbstractTableModel
{
    SearchTableModel(CachedRowSetImpl crs)
    {
        this.crs = crs;
    }

    public int getRowCount()
    {
        return crs.size();
    }

    public int getColumnCount()
    {
        return 2;
    }

    @Override
    public String getColumnName(int columnIndex)
    {
        String name = "";

        try
        {
            name = crs.getMetaData().getColumnName(columnIndex + 1);
        }
        catch (SQLException ex)
        {
            ex.printStackTrace();
        }

        return name;
    }

    public Object getValueAt(int rowIndex, int columnIndex)
    {
        Object value = null;

        try
        {
            crs.absolute(rowIndex + 1);
            value = crs.getObject(columnIndex + 1);
        }
        catch (SQLException ex)
        {
            ex.printStackTrace();
        }

        return value;
    }

    public void setRowSet(CachedRowSetImpl crs)
    {
        this.crs = crs;
    }

    private CachedRowSetImpl crs;
}
